package com.esd.bs.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Scope;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.esd.entity.other.Complaint;
import com.esd.entity.other.Report;

/**
 * 投诉登记单
 * 
 * @author liukai
 * 
 */
@Controller
@Scope(value = "prototype")
public class ReportController {
	
	@Resource
	private MongoTemplate mongoTemplate;
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@RequestMapping(value = "/web/complaintSubmit", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> complaintSubmit(Complaint complaint, String code, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String randomCode = (String) request.getSession().getAttribute("randomCode");
		if (!randomCode.equals(code)) {
			map.put("notice", false);
			map.put("message", "验证码输入错误!");
			return map;
		} else {
			String id = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
			complaint.setId(id);
			complaint.setDate(sdf.format(new Date()));
			mongoTemplate.insert(complaint);
			map.put("notice", true);
			map.put("message", "提交成功!");
			map.put("id", id);
			return map;
		}
	}

	@RequestMapping(value = "admin/queryComplaint", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView queryComplaint(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Complaint> list = mongoTemplate.findAll(Complaint.class);
		map.put("result", list);
		return new ModelAndView("queryComplaint", map);
	}

	@RequestMapping(value = "admin/queryComplaintById", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView queryComplaintById(String id, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
//		Complaint complaint = mongoTemplate.findById(Complaint.class, id);
		Complaint complaint = mongoTemplate.findById(id, Complaint.class);
		map.put("result", complaint);
		return new ModelAndView("queryComplaintById", map);
	}

	@RequestMapping(value = "admin/deleteComplaintById", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView deleteComplaintById(String id, HttpServletRequest request) {
//		Complaint complaint = mongoDBDao.findById(Complaint.class, id);
		Complaint complaint = mongoTemplate.findById(id, Complaint.class);
		mongoTemplate.remove(complaint);
		return new ModelAndView("redirect:/admin/queryComplaint");
	}

	@RequestMapping(value = "admin/exportComplaintById", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView exportComplaintById(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String fileName = "ss_" + sdf.format(new Date()) + ".xml";
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
//		Complaint complaint = mongoDBDao.findById(Complaint.class, id);
		Complaint complaint = mongoTemplate.findById(id, Complaint.class);
		PrintWriter writer = response.getWriter();
		writer.append(appendXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
		writer.append(appendXml("<!-- 申诉数据交换文件 -->"));
		writer.append(appendXml("<data>"));
		writer.append(appendXml("	<row>"));
		writer.append(appendXml("		<queryno>" + complaint.getId() + "</queryno><!-- 查询编号 -->"));
		writer.append(appendXml("		<sex>" + complaint.getGender() + "</sex><!-- 性别 -->"));
		writer.append(appendXml("		<name>" + complaint.getName() + "</name><!-- 姓名 -->"));
		writer.append(appendXml("		<tel>" + complaint.getPhone() + "</tel><!-- 您的联系电话 -->"));
//		writer.append(appendXml("		<adress>" + complaint.getAdress() + "</adress><!-- 您的通讯地址 -->"));
		writer.append(appendXml("		<email></email>"));
		writer.append(appendXml("		<prosaddrtype>" + complaint.getCity() + "</prosaddrtype><!-- 被申诉方地址 -->"));
		writer.append(appendXml("		<prosaddr>" + complaint.getLocal() + "</prosaddr><!-- 被申诉方详细地址 -->"));
		writer.append(appendXml("		<tel2>" + complaint.getNumber() + "</tel2><!-- 被申诉方电话 -->"));
		writer.append(appendXml("		<entname>" + complaint.getDesignation() + "</entname><!-- 被申诉方名称 -->"));
		writer.append(appendXml("		<goodstype>" + complaint.getGoods() + "</goodstype><!-- 商品/服务 -->"));
		writer.append(appendXml("		<goodsname>" + complaint.getGoods_name() + "</goodsname><!-- 商品类别 -->"));
		writer.append(appendXml("		<signtype>" + complaint.getBrand() + "</signtype><!-- 品牌类型 -->"));
		writer.append(appendXml("		<model>" + complaint.getModel() + "</model><!-- 型号 -->"));
//		writer.append(appendXml("		<count>" + complaint.getCount() + "</count><!-- 数量 -->"));
		writer.append(appendXml("		<money>" + complaint.getPrice() + "</money><!-- 价格 -->"));
//		writer.append(appendXml("		<voucher>" + complaint.getVoucher() + "</voucher><!-- 凭证 -->"));
		writer.append(appendXml("		<happdate>" + complaint.getYear2() + "-" + (complaint.getMonth2().length() > 1 ? complaint.getMonth2() : "0" + complaint.getMonth2()) + "-" + (complaint.getDay2().length() > 1 ? complaint.getDay2() : "0" + complaint.getDay2()) + "</happdate><!-- 发生时间 -->"));
		writer.append(appendXml("		<shortsitu>" + complaint.getContent() + "</shortsitu><!-- 简要情况 -->"));
		writer.append(appendXml("		<buydate>" + complaint.getYear() + "-" + (complaint.getMonth().length() > 1 ? complaint.getMonth() : "0" + complaint.getMonth()) + "-" + (complaint.getDay().length() > 1 ? complaint.getDay() : "0" + complaint.getDay()) + "</buydate><!-- 购买时间 -->"));
		writer.append(appendXml("	<row>"));
		writer.append(appendXml("<data>"));
		writer.close();
		return null;
	}
	
	
	@RequestMapping(value = "admin/exportComplaint")
	@ResponseBody
	public void exportComplaint(String str, HttpServletRequest request, HttpServletResponse response) throws IOException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String fileName = "ss" + sdf.format(new Date()) + ".xml";
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
		String[] strs = str.split(",");
		PrintWriter writer = response.getWriter();
		writer.append(appendXml("  <?xml version=\"1.0\" encoding=\"UTF-8\" ?> "));
		writer.append(appendXml("- <!--  申诉数据交换文件 "));
		writer.append(appendXml("  --> "));
		writer.append(appendXml("- <data>"));
		for (String id : strs) {
//			Complaint complaint = mongoDBDao.findById(Complaint.class, id);
			Complaint complaint = mongoTemplate.findById(id, Complaint.class);
			writer.append(appendXml("- <row>"));
			writer.append(appendXml("- <queryno>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getId() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </queryno>"));
			writer.append(appendXml("- <!--  查询编号 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <sex>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getGender() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </sex>"));
			writer.append(appendXml("- <!--  性别 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <name>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getName() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </name>"));
			writer.append(appendXml("- <!--  姓名 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <tel>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getPhone() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </tel>"));
			writer.append(appendXml("- <!--  您的联系电话 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <email>"));
			writer.append(appendXml("- <![CDATA[ "));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </email>"));
			writer.append(appendXml("- <prosaddrtype>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getCity() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </prosaddrtype>"));
			writer.append(appendXml("- <!--  被申诉方地址 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <prosaddr>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getLocal() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </prosaddr>"));
			writer.append(appendXml("- <!--  被申诉方详细地址 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <tel2>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getNumber() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </tel2>"));
			writer.append(appendXml("- <!--  被申诉方电话 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <entname>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getDesignation() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </entname>"));
			writer.append(appendXml("- <!--  被申诉方名称 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <goodstype>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getGoods() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </goodstype>"));
			writer.append(appendXml("- <!--  商品/服务 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <goodsname>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getGoods_name() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </goodsname>"));
			writer.append(appendXml("- <!--  商品类别 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <signname>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getBrand() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </signname>"));
			writer.append(appendXml("- <!--  品牌名称 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <model>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getModel() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </model>"));
			writer.append(appendXml("- <!--  型号 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <money>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getPrice() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </money>"));
			writer.append(appendXml("- <!--  价格 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <happdate>"));
			writer.append(appendXml("- <![CDATA[ "+ complaint.getYear2() + "-" + (complaint.getMonth2().length() > 1 ? complaint.getMonth2() : "0" + complaint.getMonth2()) + "-" + (complaint.getDay2().length() > 1 ? complaint.getDay2() : "0" + complaint.getDay2()) +" 00:00:00"));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </happdate>"));
			writer.append(appendXml("- <!--  发生时间 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <shortsitu>"));
			writer.append(appendXml("- <![CDATA[ " + complaint.getContent() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </shortsitu>"));
			writer.append(appendXml("- <!--  简要情况 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <buydate>"));
			writer.append(appendXml("- <![CDATA[ "+ complaint.getYear() + "-" + (complaint.getMonth().length() > 1 ? complaint.getMonth() : "0" + complaint.getMonth()) + "-" + (complaint.getDay().length() > 1 ? complaint.getDay() : "0" + complaint.getDay()) +" 00:00:00"));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </buydate>"));
			writer.append(appendXml("- <!--  购买时间 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <crtime>"));
			writer.append(appendXml("- <![CDATA[ "+complaint.getDate()+""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </crtime>"));
			writer.append(appendXml("- <!--  提交时间 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("  </row>"));
		}
		writer.append(appendXml("  </data>"));
		writer.close();
	}

	@RequestMapping(value = "admin/deleteComplaint")
	@ResponseBody
	public ModelAndView deleteComplaint(String str, HttpServletRequest request, HttpServletResponse response) throws IOException {
		String[] strs = str.split(",");
		for (String id : strs) {
//			Complaint complaint = mongoDBDao.findById(Complaint.class, id);
			Complaint complaint = mongoTemplate.findById(id, Complaint.class);
			mongoTemplate.remove(complaint);
		}
		return new ModelAndView("redirect:/admin/queryComplaint");
	}
	
	
	
	@RequestMapping(value = "/web/reportSubmit", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> reportSubmit(Report report, String code, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String randomCode = (String) request.getSession().getAttribute("randomCode");
		if (!randomCode.equals(code)) {
			map.put("notice", false);
			map.put("message", "验证码输入错误!");
			return map;
		} else {
			String id = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
			report.setId(id);
			report.setDate(sdf.format(new Date()));
			mongoTemplate.insert(report);
			map.put("notice", true);
			map.put("message", "提交成功!");
			map.put("id", id);
			return map;
		}
	}

	
	public String appendXml (String xml){
		return xml + "\r\n";
	}
	
	
	
	
	
	
	@RequestMapping(value = "admin/queryReport", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView queryReport(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Report> list = mongoTemplate.findAll(Report.class);
		map.put("result", list);
		return new ModelAndView("queryReport", map);
	}

	@RequestMapping(value = "admin/queryReportById", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView queryReportById(String id, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
//		Report report = mongoDBDao.findById(Report.class, id);
		Report report = mongoTemplate.findById(id, Report.class);
		map.put("result", report);
		return new ModelAndView("queryReportById", map);
	}

	@RequestMapping(value = "admin/deleteReportById", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView deleteReportById(String id, HttpServletRequest request) {
//		Report report = mongoDBDao.findById(Report.class, id);
		Report report = mongoTemplate.findById(id, Report.class);
		mongoTemplate.remove(report);
		return new ModelAndView("redirect:/admin/queryReport");
	}
	
	@RequestMapping(value = "admin/deleteReport")
	@ResponseBody
	public ModelAndView deleteReport(String str, HttpServletRequest request, HttpServletResponse response) throws IOException {
		String[] strs = str.split(",");
		for (String id : strs) {
//			Report report = mongoDBDao.findById(Report.class, id);
			Report report = mongoTemplate.findById(id, Report.class);
			mongoTemplate.remove(report);
		}
		return new ModelAndView("redirect:/admin/queryReport");
	}
	
	@RequestMapping(value = "admin/exportReportById", method = RequestMethod.GET)
	@ResponseBody
	public void exportReportById(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String fileName = "jb_" + sdf.format(new Date()) + ".xml";
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
//		Report report = mongoDBDao.findById(Report.class, id);
		Report report = mongoTemplate.findById(id, Report.class);
		PrintWriter writer = response.getWriter();
		writer.append(appendXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
		writer.append(appendXml("<!-- 举报数据交换文件 -->"));
		writer.append(appendXml("<data>"));
		writer.append(appendXml("	<row>"));
		writer.append(appendXml("		<queryno>" + report.getId() + "</queryno><!-- 查询编号 -->"));
		writer.append(appendXml("		<sex>" + report.getGender() + "</sex><!-- 性别 -->"));
		writer.append(appendXml("		<name>" + report.getName() + "</name><!-- 姓名 -->"));
		writer.append(appendXml("		<tel>" + report.getPhone() + "</tel><!-- 您的联系电话 -->"));
		writer.append(appendXml("		<email></email>"));
		writer.append(appendXml("		<prosaddrtype>" + report.getCity() + "</prosaddrtype><!-- 被申诉方地址 -->"));
		writer.append(appendXml("		<prosaddr>" + report.getLocal() + "</prosaddr><!-- 被申诉方详细地址 -->"));
		writer.append(appendXml("		<tel2>" + report.getNumber() + "</tel2><!-- 被申诉方电话 -->"));
		writer.append(appendXml("		<entname>" + report.getDesignation() + "</entname><!-- 被申诉方名称 -->"));
		writer.append(appendXml("		<goodstype>" + report.getGoods() + "</goodstype><!-- 商品/服务 -->"));
		writer.append(appendXml("		<goodsname>" + report.getGoods_name() + "</goodsname><!-- 商品类别 -->"));
		writer.append(appendXml("		<shortsitu>" + report.getContent() + "</shortsitu><!-- 简要情况 -->"));
		writer.append(appendXml("		<DEMAND>" + (report.getLook_into() != "" ? report.getLook_into() : "") + (report.getInvestigate() != "" ? "," + report.getInvestigate() : "") + (report.getSecrecy() != "" ? "," + report.getSecrecy() : "") + (report.getCommunication() != "" ? "," + report.getCommunication() : "") + (report.getAward() != "" ? "," + report.getAward() : "") + "</DEMAND><!-- 举报人要求 -->"));
		writer.append(appendXml("		<happdate>" + report.getYear() + "-" + (report.getMonth().length() > 1 ? report.getMonth() : "0" + report.getMonth()) + "-" + (report.getDay().length() > 1 ? report.getDay() : "0" + report.getDay()) + "</happdate><!-- 发生时间 -->"));
		writer.append(appendXml("	<row>"));
		writer.append(appendXml("<data>"));
		writer.close();
	}
	
	
	
	@RequestMapping(value = "admin/exportReport")
	@ResponseBody
	public void exportReport(String str, HttpServletRequest request, HttpServletResponse response) throws IOException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String fileName = "jb" + sdf.format(new Date()) + ".xml";
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
		String[] strs = str.split(",");
		PrintWriter writer = response.getWriter();
		writer.append(appendXml("  <?xml version=\"1.0\" encoding=\"UTF-8\" ?> "));
		writer.append(appendXml("- <!--  举报数据交换文件 "));
		writer.append(appendXml("  --> "));
		writer.append(appendXml("- <data>"));
		for (String id : strs) {
//			Report report = mongoDBDao.findById(Report.class, id);
			Report report = mongoTemplate.findById(id, Report.class);
			writer.append(appendXml("- <row>"));
			writer.append(appendXml("- <queryno>"));
			writer.append(appendXml("- <![CDATA[ " + report.getId() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </queryno>"));
			writer.append(appendXml("- <!--  查询编号 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <sex>"));
			writer.append(appendXml("- <![CDATA[ " + report.getGender() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </sex>"));
			writer.append(appendXml("- <!--  性别 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <name>"));
			writer.append(appendXml("- <![CDATA[ " + report.getName() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </name>"));
			writer.append(appendXml("- <!--  姓名 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <tel>"));
			writer.append(appendXml("- <![CDATA[ " + report.getPhone() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </tel>"));
			writer.append(appendXml("- <!--  您的联系电话 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <email>"));
			writer.append(appendXml("- <![CDATA[ "));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </email>"));
			writer.append(appendXml("- <prosaddrtype>"));
			writer.append(appendXml("- <![CDATA[ " + report.getCity() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </prosaddrtype>"));
			writer.append(appendXml("- <!--  被申诉方地址 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <prosaddr>"));
			writer.append(appendXml("- <![CDATA[ " + report.getLocal() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </prosaddr>"));
			writer.append(appendXml("- <!--  被申诉方详细地址 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <tel2>"));
			writer.append(appendXml("- <![CDATA[ " + report.getNumber() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </tel2>"));
			writer.append(appendXml("- <!--  被申诉方电话 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <entname>"));
			writer.append(appendXml("- <![CDATA[ " + report.getDesignation() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </entname>"));
			writer.append(appendXml("- <!--  被申诉方名称 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <goodstype>"));
			writer.append(appendXml("- <![CDATA[ " + report.getGoods() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </goodstype>"));
			writer.append(appendXml("- <!--  商品/服务 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <goodsname>"));
			writer.append(appendXml("- <![CDATA[ " + report.getGoods_name() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </goodsname>"));
			writer.append(appendXml("- <!--  商品名称 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <shortsitu>"));
			writer.append(appendXml("- <![CDATA[ " + report.getContent() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </shortsitu>"));
			writer.append(appendXml("- <!--  简要情况 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <demand>"));
			writer.append(appendXml("- <![CDATA[ " + (report.getLook_into() != "" ? report.getLook_into() : "") + (report.getInvestigate() != "" ? "," + report.getInvestigate() : "") + (report.getSecrecy() != "" ? "," + report.getSecrecy() : "") + (report.getCommunication() != "" ? "," + report.getCommunication() : "") + (report.getAward() != "" ? "," + report.getAward() : "") + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </demand>"));
			writer.append(appendXml("- <!--  举报人要求 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <happdate>"));
			writer.append(appendXml("- <![CDATA[ " + report.getYear() + "-" + (report.getMonth().length() > 1 ? report.getMonth() : "0" + report.getMonth()) + "-" + (report.getDay().length() > 1 ? report.getDay() : "0" + report.getDay()) + " 00:00:00"));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </happdate>"));
			writer.append(appendXml("- <!--  发生时间 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <password>"));
			writer.append(appendXml("- <![CDATA[ " + report.getPassword() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </password>"));
			writer.append(appendXml("- <!--  设定的密码 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("- <crtime>"));
			writer.append(appendXml("- <![CDATA[ " + report.getDate() + ""));
			writer.append(appendXml("  ]]> "));
			writer.append(appendXml("  </crtime>"));
			writer.append(appendXml("- <!--  提交时间 "));
			writer.append(appendXml("  --> "));
			writer.append(appendXml("  </row>"));
		}
		writer.append(appendXml("  </data>"));
		writer.close();
	}
	
}
